package main

import (
	"fmt"
	"github.com/PuerkitoBio/goquery"
	//"io/ioutil"
	"io/ioutil"
	"log"
	"strings"
	"go/doc"
)

type Href struct {
	title    string
	href     string
	filename string
}

func ExampleScrape() {
	var prefix string = "http://byrushan.com/projects/material-admin/app/2.0/jquery/bs4/";
	doc, err := goquery.NewDocument(prefix + "typography.html")

	if err != nil {
		fmt.Println(err)
		log.Fatal(err)
	}

	s := doc.Find(".navigation").First()

	s.Find("a").Each(func(j int, a *goquery.Selection) {

		band := a.AttrOr("href", "nil")
		title := a.Text()
		title = strings.Replace(title, " ", "", -1)

		fmt.Printf("Review %d: - %s ", band, title)
		if len(band) > 4 {

			html := getContent(prefix + band)
			var filename string = title + ".vue"
			var d1 = []byte(html)
			ioutil.WriteFile(filename, d1, 0666)
			fmt.Printf("%s is created \n" ,filename)
		}
	})

}

func getContent(url string) string {

	doc, err := goquery.NewDocument(url)
	if err != nil {
		log.Fatal(err)
	}
	s := doc.Find("section.content").First()
	s.Find("footer").Remove()

	content, _ := s.Html()
	return "<template><div>" + content + "</div></template>"

}

func main() {
	ExampleScrape()
	html := getContent("http://byrushan.com/projects/material-admin/app/2.0/jquery/bs4/typography.html")
	fmt.Println(len(html))
	//var d1 = []byte(html)
	//ioutil.WriteFile("Typography.vue", d1, 0666)
}
